package com.example.runlian.controller;

import com.example.runlian.pojo.*;
import com.example.runlian.service.DesInfoService;
import com.example.runlian.service.MainTitleService;
import com.example.runlian.service.PictureService;
import com.example.runlian.service.SecondTitleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("index")
public class IndexJsonController {

    @Autowired
    @Qualifier("defaultInfo")
    private DefaultInfo defaultInfo;
    @Autowired
    @Qualifier("mainTitleServiceImpl")
    private MainTitleService mainTitleService;
    @Autowired
    private PageInfo pageInfo;
    @Autowired
    private SecondTitleService secondTitleService;
    @Autowired
    private DesInfoService desInfoService;
    @Autowired
    private PictureService pictureService;

    /**
     * 返回 主标题信息 mainTitle
     */
    @ResponseBody
    @RequestMapping("maintitle")
    public String getMainTitle(){
        return mainTitleService.queryMainTitleByMid(defaultInfo.getMid());
    }

    /**
     * 返回 副标信息
     */
    @RequestMapping("secondtitle")
    @ResponseBody
    public List<SecondTitle> getSecondTitle(){
        //默认返回第一页的信息,每页显示4条数据
        pageInfo.setSize(4);
        pageInfo.setPage(1);
        pageInfo.setQueryMid(defaultInfo.getMid());
        List<SecondTitle> secondTitleByMid = secondTitleService.getSecondTitleByMid(pageInfo);
        return secondTitleByMid;
    }

    /**
     * 返回 描述信息
     */
    @ResponseBody
    @RequestMapping("desinfo")
    public List<DesInfo> getDesInfo(PageInfo pageInfo){
        pageInfo.setQueryMid(defaultInfo.getMid());
        List<DesInfo> desInfos = desInfoService.getDesInfo(pageInfo);
        return desInfos;
    }

    /**
     *  获取指定 mid下的描述信息总页数
     */
    @ResponseBody
    @RequestMapping("getdesinfonumbymid")
    public Integer getDesInfoNumByMid(){
        return desInfoService.queryDesInfoNumByMid(defaultInfo.getMid());
    }


    /**
     * 返回 图片名
     */
    @ResponseBody
    @RequestMapping("picname")
    public List<Picture> getPicName(){
        List<Picture> pictures = pictureService.queryPictureByMid(defaultInfo.getMid());
        return pictures;
    }
}
